/**
 * @Description: 全局数据状态事件统一处理
 *
 * @author: liuxiuqian
 *
 * @date: 2020/6/9
 */
import {appStateActions} from "../globalState"


class Actions {

  actions = {
    getGlobalState: appStateActions.getGlobalState,
    setGlobalState: appStateActions.setGlobalState,
    delGlobalState: appStateActions.delGlobalState
  };

  getGlobalState(args) {
    const globalState = this.actions.getGlobalState();
    // 判断是否为空 为空直接返回所有数据
    // eslint-disable-next-line no-void
    if(args === void 0){
      return globalState
    }
    // 获取单个值
    if(typeof(args) === 'string'){
      return args in globalState ? globalState[args] : ""
    }
    // 多参数数组的形式传入
    if(Array.isArray(args)){
      const reObj = {}
      args.forEach((item)=>{
        if(item in globalState){
          reObj[item] = globalState[item]
        }
      })
      return reObj;
    }
    // 查不到返回空
    return ""
  }

  setGlobalState(args) {
    this.actions.setGlobalState(args);
  }

  delGlobalState(){
    this.actions.delGlobalState();
  }
}

const actions = new Actions();
export default actions;
